package ar.edu.utn.frre.sistop.simumem.fragments;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import ar.edu.utn.frre.sistop.simumem.R;
import ar.edu.utn.frre.sistop.simumem.model.Proceso;
import ar.edu.utn.frre.sistop.simumem.model.Resultado;

public class StatisticAdapter extends BaseAdapter {

	private ArrayList<Proceso> mData;
	private Resultado mResultado;
	private LayoutInflater mInflater = null;

	static class ViewHolder {
		TextView tvProcessId;
		TextView tvProcessReturnTime;
		TextView tvProcessWaitTime;
	}

	public StatisticAdapter(Context c, ArrayList<Proceso> d, Resultado r) {
		this.mData = d;
		this.mResultado = r;
		mInflater = LayoutInflater.from(c);
	}

	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public Object getItem(int position) {
		return mData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_statistic, parent, false);
			holder = new ViewHolder();
			holder.tvProcessId = (TextView) convertView
					.findViewById(R.id.tvStatisticItem_idProcess);
			holder.tvProcessReturnTime = (TextView) convertView
					.findViewById(R.id.tvStatisticItem_processReturnTime);
			holder.tvProcessWaitTime = (TextView) convertView
					.findViewById(R.id.tvStatisticItem_processWaitTime);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		Proceso proceso = mData.get(position);
		holder.tvProcessId.setText(String.valueOf(proceso.getId()));
		holder.tvProcessReturnTime.setText(String.valueOf(mResultado.getTiemposRetorno().get(proceso)));
		holder.tvProcessWaitTime.setText(String.valueOf(mResultado.getTiemposEspera().get(proceso)));
		return convertView;
	}

}
